'use strict'

var https = require('https');
var fs = require('fs');

var express = require('express');
var serveIndex = require('serve-index');



var app = express();
app.use(serveIndex('./public'));
app.use(express.static('./public'));
/*
app.all('*', function (req, res, next) {
	// 设置请求头为允许跨域
	res.header('Access-Control-Allow-Origin', '*');
	res.header('Cross-Origin-Embedder-Policy', 'require-corp');
	res.header('Cross-Origin-Opener-Policy', 'same-origin');
	// 设置服务器支持的所有头信息字段
	res.header('Access-Control-Allow-Headers', 'Content-Type, Content-Length, Authorization, Accept, X-Requested-With , yourHeaderFeild, sessionToken');
	// 设置服务器支持的所有跨域请求的方法
	res.header('Access-Control-Allow-Methods', 'PUT, POST, GET, DELETE, OPTIONS');
	//if (req.method.toLowerCase() == 'options') {
	//	res.send(200);  // 让options尝试请求快速结束
	//} else {
		next();
	//}
  });
  */
var options = {
	key : fs.readFileSync('./cert/www.iaiia.site.key'),
	cert: fs.readFileSync('./cert/www.iaiia.site_bundle.pem')
}

var https_server = https.createServer(options, app);
https_server.listen(443);